using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MapPanel;

namespace CityLamp
{
    public partial class TimingForm : Form
    {
        private MainForm parentForm = null;
        public TimingForm(MainForm form)
        {
            InitializeComponent();
            this.parentForm = form;
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonOk_Click(object sender, EventArgs e)
        {
            if (this.parentForm == null)
                return;

            mapControl.NODESWITCHTIME nodeSwitchTime = new mapControl.NODESWITCHTIME();

            nodeSwitchTime.circuit1SwitchTime.TurnOnHour = (byte)this.TurnOnTimePicker1.Value.Hour;
            nodeSwitchTime.circuit1SwitchTime.TurnOnMinute = (byte)this.TurnOnTimePicker1.Value.Minute;

            nodeSwitchTime.circuit2SwitchTime.TurnOnHour = (byte)this.TurnOnTimePicker2.Value.Hour;
            nodeSwitchTime.circuit2SwitchTime.TurnOnMinute = (byte)this.TurnOnTimePicker2.Value.Minute;

            nodeSwitchTime.circuit3SwitchTime.TurnOnHour = (byte)this.TurnOnTimePicker3.Value.Hour;
            nodeSwitchTime.circuit3SwitchTime.TurnOnMinute = (byte)this.TurnOnTimePicker3.Value.Minute;

            nodeSwitchTime.circuit4SwitchTime.TurnOnHour = (byte)this.TurnOnTimePicker4.Value.Hour;
            nodeSwitchTime.circuit4SwitchTime.TurnOnMinute = (byte)this.TurnOnTimePicker4.Value.Minute;

            nodeSwitchTime.circuit5SwitchTime.TurnOnHour = (byte)this.TurnOnTimePicker5.Value.Hour;
            nodeSwitchTime.circuit5SwitchTime.TurnOnMinute = (byte)this.TurnOnTimePicker5.Value.Minute;

            nodeSwitchTime.circuit6SwitchTime.TurnOnHour = (byte)this.TurnOnTimePicker6.Value.Hour;
            nodeSwitchTime.circuit6SwitchTime.TurnOnMinute = (byte)this.TurnOnTimePicker6.Value.Minute;

            nodeSwitchTime.circuit7SwitchTime.TurnOnHour = (byte)this.TurnOnTimePicker7.Value.Hour;
            nodeSwitchTime.circuit7SwitchTime.TurnOnMinute = (byte)this.TurnOnTimePicker7.Value.Minute;

            nodeSwitchTime.circuit8SwitchTime.TurnOnHour = (byte)this.TurnOnTimePicker8.Value.Hour;
            nodeSwitchTime.circuit8SwitchTime.TurnOnMinute = (byte)this.TurnOnTimePicker8.Value.Minute;

            nodeSwitchTime.circuit1SwitchTime.TurnOffHour = (byte)this.TurnOffTimePicker1.Value.Hour;
            nodeSwitchTime.circuit1SwitchTime.TurnOffMinute = (byte)this.TurnOffTimePicker1.Value.Minute;

            nodeSwitchTime.circuit2SwitchTime.TurnOffHour = (byte)this.TurnOffTimePicker2.Value.Hour;
            nodeSwitchTime.circuit2SwitchTime.TurnOffMinute = (byte)this.TurnOffTimePicker2.Value.Minute;

            nodeSwitchTime.circuit3SwitchTime.TurnOffHour = (byte)this.TurnOffTimePicker3.Value.Hour;
            nodeSwitchTime.circuit3SwitchTime.TurnOffMinute = (byte)this.TurnOffTimePicker3.Value.Minute;

            nodeSwitchTime.circuit4SwitchTime.TurnOffHour = (byte)this.TurnOffTimePicker4.Value.Hour;
            nodeSwitchTime.circuit4SwitchTime.TurnOffMinute = (byte)this.TurnOffTimePicker4.Value.Minute;

            nodeSwitchTime.circuit5SwitchTime.TurnOffHour = (byte)this.TurnOffTimePicker5.Value.Hour;
            nodeSwitchTime.circuit5SwitchTime.TurnOffMinute = (byte)this.TurnOffTimePicker5.Value.Minute;

            nodeSwitchTime.circuit6SwitchTime.TurnOffHour = (byte)this.TurnOffTimePicker6.Value.Hour;
            nodeSwitchTime.circuit6SwitchTime.TurnOffMinute = (byte)this.TurnOffTimePicker6.Value.Minute;

            nodeSwitchTime.circuit7SwitchTime.TurnOffHour = (byte)this.TurnOffTimePicker7.Value.Hour;
            nodeSwitchTime.circuit7SwitchTime.TurnOffMinute = (byte)this.TurnOffTimePicker7.Value.Minute;

            nodeSwitchTime.circuit8SwitchTime.TurnOffHour = (byte)this.TurnOffTimePicker8.Value.Hour;
            nodeSwitchTime.circuit8SwitchTime.TurnOffMinute = (byte)this.TurnOffTimePicker8.Value.Minute;

            this.parentForm.SetControllerSwitchTime(nodeSwitchTime);
            this.Close();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                TurnOnTimePicker2.Enabled = false;
                TurnOffTimePicker2.Enabled = false;
                TurnOnTimePicker2.Value = TurnOnTimePicker1.Value;
                TurnOffTimePicker2.Value = TurnOffTimePicker1.Value;

                TurnOnTimePicker3.Enabled = false;
                TurnOffTimePicker3.Enabled = false;
                TurnOnTimePicker3.Value = TurnOnTimePicker1.Value;
                TurnOffTimePicker3.Value = TurnOffTimePicker1.Value;

                TurnOnTimePicker4.Enabled = false;
                TurnOffTimePicker4.Enabled = false;
                TurnOnTimePicker4.Value = TurnOnTimePicker1.Value;
                TurnOffTimePicker4.Value = TurnOffTimePicker1.Value;

                TurnOnTimePicker5.Enabled = false;
                TurnOffTimePicker5.Enabled = false;
                TurnOnTimePicker5.Value = TurnOnTimePicker1.Value;
                TurnOffTimePicker5.Value = TurnOffTimePicker1.Value;

                TurnOnTimePicker6.Enabled = false;
                TurnOffTimePicker6.Enabled = false;
                TurnOnTimePicker6.Value = TurnOnTimePicker1.Value;
                TurnOffTimePicker6.Value = TurnOffTimePicker1.Value;

                TurnOnTimePicker7.Enabled = false;
                TurnOffTimePicker7.Enabled = false;
                TurnOnTimePicker7.Value = TurnOnTimePicker1.Value;
                TurnOffTimePicker7.Value = TurnOffTimePicker1.Value;

                TurnOnTimePicker8.Enabled = false;
                TurnOffTimePicker8.Enabled = false;
                TurnOnTimePicker8.Value = TurnOnTimePicker1.Value;
                TurnOffTimePicker8.Value = TurnOffTimePicker1.Value;
            }
            else
            {
                TurnOnTimePicker2.Enabled = true;
                TurnOffTimePicker2.Enabled = true;
                TurnOnTimePicker3.Enabled = true;
                TurnOffTimePicker3.Enabled = true;
                TurnOnTimePicker4.Enabled = true;
                TurnOffTimePicker4.Enabled = true;
                TurnOnTimePicker5.Enabled = true;
                TurnOffTimePicker5.Enabled = true;
                TurnOnTimePicker6.Enabled = true;
                TurnOffTimePicker6.Enabled = true;
                TurnOnTimePicker7.Enabled = true;
                TurnOffTimePicker7.Enabled = true;
                TurnOnTimePicker8.Enabled = true;
                TurnOffTimePicker8.Enabled = true;
            }
        }
    }
}
